<?php

namespace Lib;

class Tools
{
    /**
     * Xhprof  开始
     *
     */
    public static function xhprofStart()
    {
        xhprof_enable();
    }

    /**
     * Xhprof 结束
     *
     */
    public static function xhprofEnd()
    {
        $xhprofData = xhprof_disable();
        $xhprofRoot = ROOT_PATH . '/xhprof/xhprof_lib/';
        include_once $xhprofRoot . "utils/xhprof_lib.php";
        include_once $xhprofRoot . "utils/xhprof_runs.php";

        $xhprof_runs = new \XHProfRuns_Default();
        $run_id      = $xhprof_runs->save_run($xhprofData, "xhprof_foo");

        echo "<a href='http://www.hd.com/xhprof/xhprof_html/index.php?run={$run_id}&source=xhprof_foo'>查看分析结果</a>";
    }

    /**
     * 自定义加密函数
     *
     */
    public static function md6($str = '')
    {
        $salt = 'baoneng';

        return md5(md5($str) . $salt);
    }

    /**
     * 调整函数
     *
     * @param string $url
     */
    public static function redirect($url = '/')
    {
        header('HTTP/1.1 301 Moved Permanently');//发出301头部
        header("Location:{$url}");//跳转
    }
}